package com.huilian.iotbox.client.controller;

import com.huilian.iotbox.data.controller.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.net.URLDecoder;

@Controller
@RequestMapping
@Slf4j
public class PayPageController extends BaseController {


    /**
     * 进入支付页面
     *
     * @return
     */
    @GetMapping("/pay")
    public String simplePay(@Param("timeStamp") String timeStamp, @Param("appId") String appId,
                            @Param("signType") String signType, @Param("nonceStr") String nonceStr,
                            @Param("canUrl") String canUrl, @Param("reUrl") String reUrl) {
        log.info("微信H5支付请求");
        log.info("支付基础信息:timeStamp:{};appId:{};signType:{};nonceStr:{};",
                StringUtils.isEmpty(timeStamp)?"":URLDecoder.decode(timeStamp),
                StringUtils.isEmpty(appId)?"":URLDecoder.decode(appId),
                StringUtils.isEmpty(signType)?"":URLDecoder.decode(signType),
                StringUtils.isEmpty(nonceStr)?"":URLDecoder.decode(nonceStr));
        log.info("支付返回地址:canUrl:{};reUrl:{}",
                StringUtils.isEmpty(canUrl)?"":URLDecoder.decode(canUrl),
                StringUtils.isEmpty(reUrl)?"":URLDecoder.decode(reUrl));
        return "pay";
    }
}
